<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link rel="stylesheet" type="text/css" href="css/base.css"/>
    <link rel="stylesheet" type="text/css" href="css/login.css"/>
</head>
<body>
<!--<form>-->
<div class="main">
    <div class="title">LOGIN</div>
    <div class="mid">
        <div class="lf">
            <ul>
                <li>
                    用户名：
                </li>
                <li>
                    密码：
                </li>
            </ul>
        </div>
        <div class="lr">
            <ul>
                <li>
                    <input type="text" id="account">
                </li>
                <li>
                    <input type="password" id="password">
                </li>
            </ul>
        </div>
    </div>
    <div class="dl">
        <button type="button" id="login">登录</button>
    </div>
    <div class="no">
        ?还未有账号，去<a href="register.html">注册</a>
    </div>
</div>
<!--</form>-->
</body>
<script src="js/jquery-3.6.0.min.js"></script>
<script type="text/javascript">

    $(document).ready(function(){
        $("#login").click(function(){
            // var token = localStorage.token//拿到token
            $.ajax({
                type:'post',
                url:"http://120.76.130.104:9000/user/login",
                // headers:{
                //     "token":token
                // }
                data:{
                    account: $("#account").val(),
                    password: $("#password").val(),
                },
                success:function(data,text,xmlHttp){
                    if (data.code === '001'){
                        // console.log(data.data)
                        localStorage.setItem("name",data.data)
                        console.log("登录成功")
                        localStorage.setItem("Token",xmlHttp.getResponseHeader("Token"))
                        window.location = "index.html"
                    }else{
                        console.log("登录失败")
                    }
                    // console.log(111)
                    //不执行
                    // alert("请求成功")
                    // console.log(xmlHttp.getResponseHeader("Token"))

                    // console.log(data)
                },
                error:function (){
                    alert("请求失败")
                }
            })
        })
    })
</script>
</html>